module OauthProvider
  class Weibo < OauthBase

    def authorize_url
      'https://api.weibo.com/oauth2/authorize'
    end

    def access_url
      'https://api.weibo.com/oauth2/access_token'
    end

    def store_user_info(client)
      token_info = JSON.parse client.post('https://api.weibo.com/oauth2/get_token_info')
      uid = token_info['uid']
      return if check_uid(uid)
      user_info = JSON.parse client.get('https://api.weibo.com/2/users/show.json', params: {uid: uid})
      info = {social_id: uid, name: user_info['screen_name'], token: client.access_token,
              provider: 'weibo', expire_in: token_info['expire_in'], create_at: token_info['create_at']}
    end

    def rescue_from(exception, response: '{}')
      raise exception
    end

    def scope
      []
    end
  end
end